<?php
/**
 * Created by PhpStorm.
 * User: Huyang
 * Date: 2016/10/12
 * Time: 11:28
 */

namespace App\Http\Controllers\Api;

use App\Exceptions\ServiceException;
use App\Http\Constants\CommonExceptionConstants;
use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IUser;
use App\Http\Requests\Api\EncryptDTO;
use App\Util\ResultsVo;
use Illuminate\Http\Request;

class MiniProgramController extends Controller
{

    public $userService;

    public function __construct(IUser $userService)
    {
        $this->userService = $userService;
    }

    public function code(Request $request) {
        if (empty($request->get('code'))) {
            throw new ServiceException(CommonExceptionConstants::getMsg('code is empty'));
        }
        $data = $this->userService->program($request->get('code'));
        return response()->json(new ResultsVo(['data'=>$data]));
    }

    public function token(EncryptDTO $encryptDTO) {

        $data = $this->userService->encrypt($encryptDTO);

        return response()->json(new ResultsVo(['data'=>$data]));

    }

}